package com.ymy.vo;


import com.ymy.utils.ConstantUtil;
import com.ymy.utils.DateUtil;
import lombok.Getter;

@Getter
public class Result<T> {

    private  String  code;

    private String msg;

    private T data;

    private String  createTime = DateUtil.getdateNow();

    private  Result(String code){
        this.code = code;
    }

    private  Result(String code,T data){
        this.code = code;
        this.data = data;
    }

    private  Result(String code,String msg){
        this.code = code;
        this.msg = msg;
    }

    private  Result(String code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * 默认成功返回
     * @param <T>
     * @return
     */
    public static<T> Result<T> OK(){
        return new Result<T>(ConstantUtil.ResponeCode.SUCCESS_CODE);
    }

    /**
     * 返回带code的信息
     * @param code
     * @param <T>
     * @return
     */
    public static<T> Result<T> OK(String code){
        return new Result<T>(code);
    }


    /**
     * 返回只带code的信息
     * @param code
     * @param <T>
     * @return
     */
    public static<T> Result<T> faild(String code){
        return new Result<T>(code,ConstantUtil.ResponeCode.SYS_ERROR);
    }


    /**
     * 返回带code与提示消息的对象
     * @param code
     * @param msg
     * @param <T>
     * @return
     */
    public static<T> Result<T> faild(String code,String msg){
        return new Result<T>(code,msg);
    }



}
